package com.netx.generics.basic;
import com.netx.generics.time.Moment;

public class DefaultLogger extends AbstractLogger {

	private static final String _emptyMsg = "(no message)";
	
	protected void output(StackTraceElement place, LEVEL type, String message, Throwable t) {
		System.out.print(type+" ["+new Moment().format()+"]: "+place+": ");
		if(message != null) {
			System.out.println(message);
		}
		else {
			if(t == null) {
				System.out.println(_emptyMsg);
			}
			else {
				// t.getMessage is printed, because it's handy to see the exception message
				// right away when the stack trace is discarded or put somewhere else
				// (ex: CsvLogger). Although this is not very valuable for this Logger,
				// it's better to ensure a similar behaviour across Logger implementations.
				System.out.println(t.getMessage()==null ? _emptyMsg : t.getMessage());
			}
		}
		if(t != null) {
			t.printStackTrace(System.out);
		}
	}
}
